(function() {
  "use strict";
  APP.Views.UserInfoView = Backbone.View.extend({
    el: '#userContainer',
    events : {
      'mouseenter .avatar': 'zoomIn',
      'mouseleave .avatar': 'zoomOut',
      'click .com-management': 'comManagementShow',
      'click .gotoSettings': 'gotoSettings',
      'click .gotoGroup': 'gotoGroups'
    },
    initialize: function(params) {
      var callback = {
        obj: this,
        name: 'getUserDataSuccess'
      }
      APP.BeClient.getUserData(callback, undefined, {
        preloaderShow: false,
        preloaderHide: false
      });
    },
    getUserDataSuccess: function(data) {
      this.render(data.user);
    },
    zoomIn: function(e) {
      var $e = $(e.currentTarget);
      $e.stop().animate({'height': 150});
    },
    zoomOut: function(e) {
      var $e = $(e.currentTarget);
      $e.stop().animate({'height': 50});
    },
    comManagementShow: function(e) {
      e.preventDefault();
      new APP.Views.DialogComManagementView({
        menuView: APP.mainView
      });
    },
    gotoSettings: function(e) {
      e.preventDefault();
      Backbone.history.navigate("uzytkownicy", {
        trigger: true
      });
    },
    gotoGroups: function(e) {
      e.preventDefault();
      Backbone.history.navigate("grupy", {
        trigger: true
      });
    },
    render: function(user) {
      var self = this;
      this.$el.html(_.template($('#userInfoTemplate').html(), {
        user: user
      }));
      this.$('.show-more-info').popover({
        html: true,
        placement: 'bottom',
        content: _.template($('#userInfoMoreTemplate').html(), {
          user: user
        }),
        trigger: 'focus'
      });
      self.$('.set-margin').css('marginRight', $('img.avatar').width() - 15);
      this.$('img.avatar').imgpreload(function() {
        self.$('.set-margin').css('marginRight', $(this).width() - 15);
      });
      return this;
    }
  });
}());